home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 18 gdiplus / gdidemo / transformations.vb < prev    next >
Encoding:
Text File  |  2001-10-02  |  3.8 KB  |  116 lines

  1. Imports System.Drawing.Drawing2D
  2.  
  3. Public Class Transformations
  4.     Inherits System.Windows.Forms.Form
  5.  
  6. #Region " Windows Form Designer generated code "
  7.  
  8.     Public Sub New()
  9.         MyBase.New()
  10.  
  11.         'This call is required by the Windows Form Designer.
  12.         InitializeComponent()
  13.  
  14.         'Add any initialization after the InitializeComponent() call
  15.  
  16.     End Sub
  17.  
  18.     'Form overrides dispose to clean up the component list.
  19.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  20.         If disposing Then
  21.             If Not (components Is Nothing) Then
  22.                 components.Dispose()
  23.             End If
  24.         End If
  25.         MyBase.Dispose(disposing)
  26.     End Sub
  27.     Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
  28.     Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
  29.     Friend WithEvents mnuTranslateRotate As System.Windows.Forms.MenuItem
  30.  
  31.     'Required by the Windows Form Designer
  32.     Private components As System.ComponentModel.Container
  33.  
  34.     'NOTE: The following procedure is required by the Windows Form Designer
  35.     'It can be modified using the Windows Form Designer.  
  36.     'Do not modify it using the code editor.
  37.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  38.         Me.MainMenu1 = New System.Windows.Forms.MainMenu()
  39.         Me.MenuItem1 = New System.Windows.Forms.MenuItem()
  40.         Me.mnuTranslateRotate = New System.Windows.Forms.MenuItem()
  41.         '
  42.         'MainMenu1
  43.         '
  44.         Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
  45.         '
  46.         'MenuItem1
  47.         '
  48.         Me.MenuItem1.Index = 0
  49.         Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuTranslateRotate})
  50.         Me.MenuItem1.Text = "Examples"
  51.         '
  52.         'mnuTranslateRotate
  53.         '
  54.         Me.mnuTranslateRotate.Index = 0
  55.         Me.mnuTranslateRotate.Text = "Translate and Rotate"
  56.         '
  57.         'Transformations
  58.         '
  59.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  60.         Me.ClientSize = New System.Drawing.Size(528, 269)
  61.         Me.Menu = Me.MainMenu1
  62.         Me.Name = "Transformations"
  63.         Me.Text = "Transformations"
  64.  
  65.     End Sub
  66.  
  67. #End Region
  68.  
  69.     Private Sub mnuTranslateRotate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuTranslateRotate.Click
  70.         ' Wait until the menu closes.
  71.         Threading.Thread.Sleep(400)
  72.  
  73.         Dim gr As Graphics = Me.CreateGraphics
  74.         gr.Clear(Color.White)
  75.  
  76.         gr.PageUnit = GraphicsUnit.Millimeter
  77.         gr.PageScale = 0.1
  78.  
  79.         ' Create a Path that we can draw multiple times.
  80.         Dim pa As New GraphicsPath()
  81.         pa.AddRectangle(New Rectangle(20, 20, 200, 100))
  82.         pa.AddEllipse(New Rectangle(30, 30, 180, 80))
  83.         ' Draw the path without any transformation.
  84.         gr.DrawPath(Pens.Black, pa)
  85.  
  86.         ' Apply a translation and redraw the path.
  87.         gr.TranslateTransform(30, 200)
  88.         gr.DrawPath(Pens.Red, pa)
  89.  
  90.         ' Apply both a translation and a rotation, and redraw the Path.
  91.         gr.ResetTransform()
  92.         gr.TranslateTransform(400, 0)
  93.         gr.RotateTransform(30)
  94.         gr.DrawPath(Pens.Green, pa)
  95.  
  96.         ' translate again, change the scale and redraw.
  97.         gr.ResetTransform()
  98.         gr.TranslateTransform(300, 200)
  99.         ' create multiple shapes that vary in angle and scale.
  100.         Dim i As Integer
  101.         Dim scaleX As Single = 1
  102.         Dim scaleY As Single = 1
  103.         For i = 1 To 6
  104.             gr.ScaleTransform(scaleX, scaleY)
  105.             gr.DrawPath(Pens.Blue, pa)
  106.             scaleX += 0.05
  107.             scaleY += 0.1
  108.         Next
  109.  
  110.         ' Destroy the Path object.
  111.         pa.Dispose()
  112.         ' Destroy the Graphics object.
  113.         gr.Dispose()
  114.     End Sub
  115. End Class
  116.